<template>
  <div class="tab-wrapper" style="position: relative;">
    <!-- <app-header :showLeft="false">
      <mt-button
        slot="right"
        v-if="role === 'manager'"
        @click="$router.push({ name: 'sendSet' })"
      >
        <img src="@/assets/images/common/setting.png" alt="" width="18" />
      </mt-button>
    </app-header> -->
    <div class="tab-main" >
      <!-- 客户 -->
      <div class="role customer" v-if="role === 'customer'">
        <!-- 退出按钮 -->
        <div class="logout" @click="logout">退出</div>
        <network :request="fetchCustomerData" ref="network0">
          <!-- 没有申请 -->
          <div
            class="empty"
            v-if="applyList !== null && applyList.length === 0"
          >
            <img src="@/assets/images/common/apply-empty.png" alt="" />
            <p>尊敬的用户，您名下没有进行中的押好贷</p>
            <p>申请记录，如需贷款请前往申请！&emsp;&emsp;&emsp;</p>
            <button
              class="btn btn-primary"
              @click="$router.push({ name: 'apply1' })"
            >
              前往申请
            </button>
           
          </div>
          <!-- 申请列表 -->
          <div
            class="applyList"
            v-else-if="applyList !== null && applyList.length > 0"
          >
            <div
              class="item"
              :class="{
                warn: value['property_state'] === '待提交',
                error: ['已关闭', '已取消'].includes(value['property_state'])
              }"
              v-for="(value, index) in applyList"
              :key="index"
            >
              <div class="head">
                <span class="name">押好贷</span>
                <span class="btn-group">
                  <button
                    v-if="
                      ['待收件', '待提交'].includes(value['property_state'])
                    "
                    @click="cancel(value['property_number'])"
                  >
                    取消申请
                  </button>
                  <button
                    v-if="
                      !['待收件', '待提交', '已取消'].includes(
                        value['property_state']
                      )
                    "
                    @click="comment(value['property_number'])"
                  >
                    评价
                  </button>
                  <button @click="check(value['property_number'])">
                    查看
                  </button>
                </span>
              </div>
              <div class="body">
                <ul>
                  <li>
                    <span class="title">申请时间</span>
                    <span class="content"
                      >{{ value["create_time"] }}
                      <i
                        class="edit"
                        v-if="value['property_state'] === '待提交'"
                        @click="edit(value['property_number'])"
                      ></i>
                    </span>
                  </li>
                  <li>
                    <span class="title">状态</span>
                    <span class="content">{{ value["property_state"] }}</span>
                  </li>
                  <li v-if="value['property_state'] === '已关闭'">
                    <span class="title">原因</span>
                    <span class="content">{{ value["estimate_value"] }}</span>
                  </li>
                  <li v-if="value['manager_name'] && value['property_state'] != '待收件'">
                    <span class="title">客户经理</span>
                    <span class="content">
                      {{ value["manager_name"] }}
                      <a
                        :href="'tel:' + value['manager_phone']"
                        v-if="value['manager_phone']"
                      ></a>
                    </span>
                  </li>
                </ul>
               
              </div>
              
            </div>
          </div>
          
        </network>
        
      </div>
      <!-- 客户经理 -->
      <div class="role manager" v-if="role === 'manager'">
        <!-- 客户经理收件设置 -->
        <!-- <mt-button
          slot="right"
          v-if="role === 'manager'"
          @click="$router.push({ name: 'sendSet' })"
        >
          <img src="@/assets/images/common/setting.png" alt="" width="18" />
        </mt-button> -->
        <div class="tabbar">
          <div
            class="tabbar-item"
            v-for="(value, index) in tabbar"
            :key="value.id"
            @click="tabActiveIndex = index"
            :class="{ active: tabActiveIndex === index }"
          >
            <span class="title"
              >{{ value.title }}
              <i class="badge" v-show="value.badge > 0">{{ value.badge }}</i>
            </span>
          </div>
          <div
            class="line"
            :style="{ transform: `translateX(${tabActiveIndex}00%)` }"
          ></div>
        </div>
        <mt-tab-container
          v-model="tabActive"
          class="tab-container"
          :swipeable="true"
          style="position:relative"
        >
          <!-- 退出按钮 -->
          <div class="logout" @click="logout">退出</div>
          <!-- 待收件 -->
          <mt-tab-container-item class="tab-container-item" id="tab-container1">
            <div class="tab-content" v-if="tabContentShow1">
              <network :request="fetchManagerData(true)" ref="network1">
                <!-- 列表为空 -->
                <div
                  class="empty"
                  v-if="dueInList !== null && dueInList.length === 0"
                >
                  <img src="@/assets/images/common/apply-empty.png" alt="" />
                  <p>尊敬的用户，您当前的待收件列表为空</p>
                </div>
                <!-- 待收件列表 -->
                <div
                  class="list list1"
                  v-else-if="dueInList !== null && dueInList.length > 0"
                  v-infinite-scroll="loadMore"
                  infinite-scroll-disabled="infiniteLoading1"
                  infinite-scroll-distance="0"
                  infinite-scroll-immediate-check="true"
                >
                  <div
                    class="item"
                    v-for="(value, index) in dueInList"
                    :key="index"
                  >
                    <div class="head">
                      <span class="name">押好贷</span>
                      <span class="btn-group">
                        <!-- <button @click="sysDispatch(value.PropertyNumber)">
                          系统转派
                        </button> -->
                        <button @click="poDispatch(value.PropertyNumber)">
                          <!-- 定向转派 -->
                          转派
                        </button>
                        <button @click="pick(value.PropertyNumber)">
                          收件
                        </button>
                      </span>
                    </div>
                    <div class="body">
                      <ul>
                        <li>
                          <span class="title">姓名</span>
                          <span class="content">
                            {{ value.PropertyUserName }}
                          </span>
                        </li>
                        <li>
                          <span class="title">手机号</span>
                          <span class="content">
                            {{
                              value.PropertyUserPhone.slice(0, 3) +
                                "****" +
                                value.PropertyUserPhone.slice(-4)
                            }}
                          </span>
                        </li>
                        <li>
                          <span class="title">身份证</span>
                          <span class="content">
                            {{
                              value.UserIdentityidentity.slice(0, 4) +
                                "**********" +
                                value.UserIdentityidentity.slice(-3)
                            }}
                          </span>
                        </li>
                        <li>
                          <span class="title">申请时间</span>
                          <span class="content">
                            {{ value.CreateTime }}
                          </span>
                        </li>
                      </ul>
                    </div>
                  </div>
                  
                </div>
              </network>
            </div>
          </mt-tab-container-item>

          <!-- 待处理 -->
          <mt-tab-container-item id="tab-container2"  class="tab-container-item">
            <div class="tab-content" v-if="tabContentShow2">
              <network :request="fetchManagerData(true)" ref="network2">
                <!-- 列表为空 -->
                <div
                  class="empty"
                  v-if="pendingList !== null && pendingList.length === 0"
                >
                  <img src="@/assets/images/common/apply-empty.png" alt="" />
                  <p>尊敬的用户，您当前的待处理列表为空</p>
                 
                </div>
                <!-- 待处理列表 -->
                <div
                  class="list list2"
                  v-else-if="pendingList !== null && pendingList.length > 0"
                  v-infinite-scroll="loadMore"
                  infinite-scroll-disabled="infiniteLoading2"
                  infinite-scroll-distance="0"
                  infinite-scroll-immediate-check="true"
                >
                  <div
                    class="item"
                    v-for="(value, index) in pendingList"
                    :key="index"
                  >
                    <div class="head">
                      <span class="name">押好贷</span>
                      <span class="btn-group">
                        <button style="height:.26rem;width:.68rem;line-height:.24rem;font-size:.14rem" @click="check(value.PropertyNumber, 1)">
                          查看
                        </button>
                        <button @click="follow(value.PropertyNumber)">
                          跟进记录
                        </button>
                        <button @click="deal(value.PropertyNumber)">
                          申请处理
                        </button>

                      </span>
                    </div>
                    <div class="body">
                      <ul>
                        <li>
                          <span class="title">姓名</span>
                          <span class="content">
                            {{ value.PropertyUserName }}
                          </span>
                        </li>
                        <li>
                          <span class="title">手机号</span>
                          <span class="content">
                            <!-- 手机号脱敏处理 注释-->
                            <!-- {{
                              value.PropertyUserPhone.slice(0, 3) +
                                "****" +
                                value.PropertyUserPhone.slice(-4)
                            }} -->
                            {{value.PropertyUserPhone}}
                            <a :href="'tel:' + value.PropertyUserPhone"></a>
                          </span>
                        </li>
                        <li>
                          <span class="title">身份证</span>
                          <span class="content">
                            <!-- 身份证好脱敏处理  注释 -->
                            <!-- {{
                              value.UserIdentityidentity.slice(0, 4) +
                                "**********" +
                                value.UserIdentityidentity.slice(-3)
                            }} -->
                            {{ value.UserIdentityidentity}}
                          </span>
                        </li>
                        <li>
                          <span class="title">申请时间</span>
                          <span class="content">
                            {{ value.CreateTime }}
                          </span>
                        </li>
                        <li v-if="value.EstimateList.length > 0">
                          <span class="title">跟进</span>
                          <span class="content column">
                            <p
                              v-for="(item, index) in value.EstimateList"
                              :key="index"
                            >
                              {{ item.estimateValue }}&ensp;{{
                                dateFormat(item.estimateDate)
                              }}
                            </p>
                          </span>
                        </li>
                      </ul>
                    </div>
                  </div>
                </div>
              </network>
            </div>
          </mt-tab-container-item>

          <!-- 已处理 -->
          <mt-tab-container-item  id="tab-container3" class="tab-container-item">
            <div class="tab-content" v-if="tabContentShow3">
               <!-- <button
                class="btn btn-primary logout"
                @click="logout"
                  >
                  退出登录
                </button> -->
              <network :request="fetchManagerData(true)" ref="network3">
                <!-- 列表为空 -->
                <div
                  class="empty"
                  v-if="processedList !== null && processedList.length === 0"
                >
                  <img src="@/assets/images/common/apply-empty.png" alt="" />
                  <p>尊敬的用户，您当前的已处理列表为空</p>
                 
                </div>
                <!-- 已处理列表 -->
                <div
                  class="list list3"
                  v-else-if="processedList !== null && processedList.length > 0"
                  v-infinite-scroll="loadMore"
                  infinite-scroll-disabled="infiniteLoading3"
                  infinite-scroll-distance="0"
                  infinite-scroll-immediate-check="true"
                >
                  <div
                    class="item"
                    v-for="(value, index) in processedList"
                    :key="index"
                  >
                    <div class="head">
                      <span class="name">押好贷</span>
                      <span class="btn-group">
                        <button style="height:.26rem;width:.68rem;line-height:.24rem;font-size:.14rem" @click="check(value.PropertyNumber, 2)">
                          查看
                        </button>
                      </span>
                    </div>
                    <div class="body">
                      <ul>
                        <li>
                          <span class="title">姓名</span>
                          <span class="content">
                            {{ value.PropertyUserName }}
                          </span>
                        </li>
                        <li>
                          <span class="title">手机号</span>
                          <span class="content">
                            <!-- {{
                              value.PropertyUserPhone.slice(0, 3) +
                                "****" +
                                value.PropertyUserPhone.slice(-4)
                            }} -->
                            {{ value.PropertyUserPhone}}
                            <a :href="'tel:' + value.PropertyUserPhone"></a>
                          </span>
                        </li>
                        <li>
                          <span class="title">身份证</span>
                          <span class="content">
                            <!-- {{
                              value.UserIdentityidentity.slice(0, 4) +
                                "**********" +
                                value.UserIdentityidentity.slice(-3)
                            }} -->
                            {{value.UserIdentityidentity}}
                          </span>
                        </li>
                        <li>
                          <span class="title">申请时间</span>
                          <span class="content">
                            {{ value.CreateTime }}
                          </span>
                        </li>
                        <li>
                          <span class="title">状态</span>
                          <span
                            class="content processed"
                            :class="{
                              closed: ['已拒绝', '客户取消'].includes(
                                value.PropertyState
                              )
                            }"
                          >
                            {{ value.PropertyState }}
                          </span>
                        </li>
                        <li v-if="value.EstimateList.length > 0">
                          <span class="title">跟进</span>
                          <span class="content column">
                            <p
                              v-for="(item, index) in value.EstimateList"
                              :key="index"
                            >
                              {{ item.estimateValue }}&ensp;{{
                                dateFormat(item.estimateDate)
                              }}
                            </p>
                          </span>
                        </li>
                        <li v-if="value.PropertyState === '已拒绝'">
                          <span class="title">原因</span>
                          <span class="content">
                            {{ value.Opinion }}&ensp;{{ value.UpdateTime }}
                          </span>
                        </li>
                      </ul>
                    </div>
                  </div>
                  
                </div>
              </network>
            </div>
          </mt-tab-container-item>
          
        </mt-tab-container>

        <!-- 弹出窗 -->
        <div class="msgbox-wrapper" v-show="applyDeal.show" @touchmove.stop>
          <div class="msgbox-mask" @click="closeMsgbox"></div>
          <div class="msgbox">
            <div class="msgbox-header">
              {{ applyDeal.title[applyDeal.type] }}
            </div>
            <div class="msgbox-content">
              <!-- 定向转派 -->
              <template v-if="applyDeal.type === 'dispatch'">
                <p>请选择该件定向转派的客户经理</p>
                <div class="pickbox" v-if="applyDeal.managerList.length > 0">
                  <span @click="togglePopup">
                    {{
                      applyDeal.managerSelect.customerName || "请选择客户经理"
                    }}
                  </span>
                </div>
                <div class="empty" v-else>
                  客户经理列表为空
                </div>
              </template>
              <!-- 跟进记录 -->
              <template v-else-if="applyDeal.type === 'follow'">
                <mt-field
                  type="textarea"
                  class="textarea"
                  placeholder="请输入跟进记录"
                  v-model="applyDeal.opinion"
                  v-hint-emoji
                ></mt-field>
              </template>
              <!-- 申请处理 -->
              <template v-else-if="applyDeal.type === 'deal'">
                <div class="select">
                  <span class="title">状态</span>
                  <mt-radio
                    v-model="applyDeal.status"
                    :options="applyDeal.options"
                  ></mt-radio>
                </div>
                <mt-field
                  type="textarea"
                  class="textarea"
                  placeholder="请填写你的意见"
                  v-model="applyDeal.opinion"
                  v-hint-emoji
                ></mt-field>
              </template>
            </div>
            <div class="msgbox-btns" @touchmove.stop.prevent>
              <button @click="closeMsgbox">取消</button>
              <button @click="handleMsgboxConfirm()">确认</button>
            </div>
          </div>
        </div>
       
      </div>
     
        
    </div>
    <mt-popup
      v-model="popupVisible"
      position="bottom"
      :modal="true"
      style="width:100%"
    >
      <mt-picker
        :showToolbar="true"
        ref="picker"
        valueKey="customerName"
        :slots="[
          {
            flex: 1,
            values: applyDeal.managerList,
            className: 'slot1',
            textAlign: 'center'
          }
        ]"
      >
        <div class="pickerToolBar">
          <button @click="togglePopup">取消</button>
          <span>客户经理选择</span>
          <button @click="pickerConfirm">确定</button>
        </div>
      </mt-picker>
    </mt-popup>
     
  </div>
</template>

<script>
import Network from "@/components/Network";
import { mapGetters } from "vuex";
import { queryApplyBillList } from "@/api";
import { cancelApply } from "@/api/customer";
import {
  pickBill,
  systemDispatch,
  managerList,
  pointDispatch,
  applyDeal,
  applyFollow
} from "@/api/manager";
import {
  roleReflectMap,
  ApplyBillStatus,
  ApplyBillStatusReflect
} from "@/utils/constant";
import { dateFormat } from "@/utils";
/* 设置分页请求的条数 */
const PageLine = 5;
// 客户经理操作单子code码
const managerOperate = {
  pass: ApplyBillStatusReflect["放款中"], //"核查通过",
  close: ApplyBillStatusReflect["已拒绝"] //"关闭申请"
};

export default {
  name: "tab2",
  components: { Network },
  data() {
    return {
      applyList: null, // 申请列表（客户）
      dueInList: null, //待收件列表（客户经理）
      pendingList: null, //待处理列表（客户经理）
      processedList: null, //已处理列表（客户经理）
      tabbar: [
        {
          title: "待收件",
          id: "tab-container1",
          badge: 0,
          code: "notFiled",
          type: "dueIn",
          page: 1
        },
        {
          title: "待处理",
          id: "tab-container2",
          badge: 0,
          code: "Pending",
          type: "pending",
          page: 1
        },
        {
          title: "已处理",
          id: "tab-container3",
          badge: 0,
          code: "Processed",
          type: "processed",
          page: 1
        }
      ],
      tabActiveIndex: +window.sessionStorage.tabActiveIndex || 0,
      tabActive: "",
      tabContentShow1: false,
      tabContentShow2: false,
      tabContentShow3: false,
      infiniteLoading1: false, //if true, infinite scroll will not be triggered
      infiniteLoading2: false,
      infiniteLoading3: false,
      /* 客户经理 模态弹窗 */
      applyDeal: {
        show: false, // 显示控制
        type: "", //类型 dispatch:转派，follow:跟进，deal:处理
        title: {
          dispatch: "转派",
          follow: "跟进记录",
          deal: "申请处理"
        },
        propertyNumber: "", //订单id
        managerList: [], // 客户经理列表（后台获取）
        managerSelect: {}, //选择的客户经理
        status: managerOperate.pass, // 默认选中 核查通过
        opinion: "", // 意见
        options: [
          {
            label: "核查通过",
            value: managerOperate.pass
          },
          {
            label: "关闭申请",
            value: managerOperate.close
          }
        ]
      },
      popupVisible: false,
      dateFormat: date => dateFormat(date, "yyyy-MM-dd hh:mm:ss") // 日期格式化（用在template中）
    };
  },
  computed: {
    ...mapGetters("user", ["role"])
  },
  watch: {
    tabActiveIndex: {
      handler(index) {
        this.tabActive = this.tabbar[index].id;
      },
      immediate: true
    },
    tabActive: {
      handler(id) {
        let index = id.slice(-1) - 0;
        this.tabActiveIndex = index - 1;

        this.$nextTick(() => {
          /* 列表切换-回到顶部 */
          const list_elem = this.$el.querySelector(`.list.list${index}`);
          list_elem && list_elem.scrollTo(0, 0);

          if (this["tabContentShow" + index] === false) {
            this["tabContentShow" + index] = true;
          } else {
            if (index === 1 && this.dueInList === null) {
              this.$refs.network1.init();
            } else if (index === 2 && this.pendingList === null) {
              this.$refs.network2.init();
            } else if (index === 3 && this.processedList === null) {
              this.$refs.network3.init();
            } else {
              this.fetchManagerData(true)();
            }
          }
        });
      },
      immediate: true
    }
  },
  created() {
    if (this.role === "manager") {
      this.$route.meta.title = document.title = "我的派件";
    }
  },
  mounted() {
    window.sessionStorage.removeItem("tabActiveIndex");
  },
  methods: {
    logout() {
      this.$messagebox({
        message: "是否确认退出?",
        showConfirmButton: true,
        showCancelButton: true,
        confirmButtonText: "是",
        cancelButtonText: "否",
        title:"温馨提示"
      }).then( res =>{
        if(res === "confirm"){
          this.$store.dispatch("logout");
          this.$toast({
            message: "退出成功",
            position: "bottom",
            duration: 1500
          });
          this.$router.push({ path: "/" });
        }
      })
      
    },
    togglePopup() {
      this.popupVisible = !this.popupVisible;
    },
    pickerConfirm() {
      this.applyDeal.managerSelect = this.$refs.picker.getValues()[0];
      this.togglePopup();
      this.handleMsgboxConfirm();
    },
    /* 获取客户数据 */
    fetchCustomerData() {
      return queryApplyBillList({
        userSign: roleReflectMap[this.role]
      }).then(res => {
        if (res.respCode === "000000") {
          if (!Array.isArray(res.params)) return;
          res.params.forEach(item => {
            /* 申请单状态code码转换为对应中文 */
            item["property_state"] =
              ApplyBillStatus[item["property_state"]].customer;
            /* 申请单创建时间转换 */
            item["create_time"] = dateFormat(
              item["create_time"],
              "yyyy-MM-dd hh:mm:ss"
            );
          });
          this.applyList = res.params;
        }
      });
    },

    /* 获取客户经理数据 */
    fetchManagerData(beginZero) {
      const index = this.tabActiveIndex,
        type = this.tabbar[index].type,
        code = this.tabbar[index].code;
      return () => {
        if (beginZero) {
          /* 重置第一页开始 */
          this.tabbar[index].page = 1;
        }
        return queryApplyBillList({
          userSign: roleReflectMap[this.role],
          ManagerCode: code,
          Page: this.tabbar[index].page,
          Line: PageLine
        }).then(res => {
          if (res.respCode === "000000") {
            /* 处理badge */
            const BatchTotalCount = res.params.BatchTotalCount;
            this.tabbar[0].badge = BatchTotalCount.notFiledCount;
            this.tabbar[1].badge = BatchTotalCount.PendingCount;
            this.tabbar[2].badge = BatchTotalCount.ProcessedCount;
            this.$forceUpdate();
            /* 处理列表 */
            const PropertyList = res.params.PropertyList;
            if (!Array.isArray(PropertyList)) return;
            PropertyList.forEach(list => {
              /* 状态code码转换为对应中文 */
              list["PropertyState"] =
                ApplyBillStatus[list["PropertyState"]].manager;
              /* 时间转换 */
              list["CreateTime"] = dateFormat(
                list["CreateTime"],
                "yyyy-MM-dd hh:mm:ss"
              );
              list["UpdateTime"] = dateFormat(
                list["UpdateTime"],
                "yyyy-MM-dd hh:mm:ss"
              );
            });
            if (this.tabbar[index].page === 1) {
              this[type + "List"] = PropertyList;
              this.tabbar[index].page += 1;
            } else {
              if (PropertyList.length > 0) {
                let list = this[type + "List"];
                list.push.apply(list, PropertyList); //vue数组的变异方法自动触发更新
                this.tabbar[index].page += 1;
              } else {
                this.$toast({
                  message: "没有更多了~",
                  position: "bottom",
                  duration: 1000
                });
              }
            }
          }
        });
      };
    },

    /* 上拉加载更多 */
    async loadMore() {
      const index = this.tabActiveIndex - 0 + 1;
      this["infiniteLoading" + index] = true;
      try {
        await this.fetchManagerData()();
      } catch (e) {}
      this["infiniteLoading" + index] = false;
    },
    /* 查看 */
    check(id, index) {
      this.$router.push({ path: "/applyDetail/" + id });
      /* 缓存当前选中的tab编号 */
      if (index) {
        window.sessionStorage.setItem("tabActiveIndex", index);
      }
    },
    /* 评价 */
    comment(id) {
      this.$router.push({ path: "/comment/" + id });
    },
    /* 编辑 */
    edit(id) {
      window.sessionStorage.setItem("orderId", id);
      this.$router.push({ name: "apply2" });
    },
    /* 取消申请 */
    cancel(id) {
      this.$messagebox({
        message: "是否确认取消该申请?",
        showConfirmButton: true,
        showCancelButton: true,
        confirmButtonText: "是",
        cancelButtonText: "否"
      }).then(res => {
        if (res === "confirm") {
          cancelApply({
            propertyNumber: id
          }).then(res => {
            if (res.respCode === "000000") {
              this.$toast({
                message: "取消成功",
                position: "bottom",
                duration: 1500
              });
              this.$refs.network0.init();
            }
          });
        }
      });
    },
    /* 客户经理-收件 */
    async pick(id) {
      await this.$messagebox.confirm("确定要收件吗?");
      pickBill({
        propertyNumber: id
      }).then(res => {
        if (res.respCode === "000000") {
          this.$toast({
            message: "收件成功",
            position: "bottom",
            duration: 1500
          });
          this.$refs.network1.init();
        }
      });
    },
    /* 客户经理-系统转派 */
    async sysDispatch(id) {
      await this.$messagebox.confirm("确定要系统转派吗?");
      systemDispatch({
        propertyNumber: id
      }).then(res => {
        if (res.respCode === "000000") {
          this.$toast({
            message: "系统转派成功",
            position: "bottom",
            duration: 1500
          });
          this.$refs.network1.init();
        }
      });
    },
    /* 客户经理-定向转派 */
    poDispatch(id) {
      managerList().then(res => {
        if (res.respCode === "000000") {
          this.applyDeal.managerList = res.params;
          this.applyDeal.propertyNumber = id;
          this.applyDeal.type = "dispatch";
          // this.applyDeal.show = true;
          this.togglePopup();
        }
      });
    },
    /* 客户经理-跟进记录 */
    follow(id) {
      this.applyDeal.propertyNumber = id;
      this.applyDeal.type = "follow";
      this.applyDeal.show = true;
    },
    /* 客户经理-申请处理 */
    deal(id) {
      this.applyDeal.propertyNumber = id;
      this.applyDeal.type = "deal";
      this.applyDeal.show = true;
    },
    /* 弹窗关闭 */
    closeMsgbox() {
      this.applyDeal.managerSelect = {};
      this.applyDeal.status = managerOperate.pass;
      this.applyDeal.opinion = "";
      this.applyDeal.show = false;
    },
    /* 弹窗确认按钮处理 */
    handleMsgboxConfirm() {
      if (this.applyDeal.type === "dispatch") {
        if (this.applyDeal.managerList.length === 0) return; //客户经理列表为空
        if (!this.applyDeal.managerSelect.userId) {
          this.$toast({
            message: "请选择客户经理",
            position: "bottom",
            duration: 1500
          });
          return;
        }
        pointDispatch({
          propertyNumber: this.applyDeal.propertyNumber,
          ManagerUserId: this.applyDeal.managerSelect.userId
        }).then(res => {
          if (res.respCode === "000000") {
            this.$toast({
              message: "定向转派成功",
              position: "bottom",
              duration: 1500
            });
            this.$refs.network1.init();
            this.closeMsgbox();
          }
        });
      } else if (this.applyDeal.type === "follow") {
        if (!this.applyDeal.opinion) {
          this.$toast({
            message: "请输入跟进记录",
            position: "bottom",
            duration: 1500
          });
          return;
        }
        applyFollow({
          propertyNumber: this.applyDeal.propertyNumber,
          estimateValue: this.applyDeal.opinion
        }).then(res => {
          if (res.respCode === "000000") {
            this.$toast({
              message: "记录成功",
              position: "bottom",
              duration: 1500
            });
            this.$refs.network2.init();
            this.closeMsgbox();
          }
        });
      } else if (this.applyDeal.type === "deal") {
        if (!this.applyDeal.status) {
          this.$toast({
            message: "请选择处理状态",
            position: "bottom",
            duration: 1500
          });
          return;
        }
        // 拒绝必须输入意见
        if (
          this.applyDeal.status === ApplyBillStatusReflect["已拒绝"] &&
          !this.applyDeal.opinion
        ) {
          this.$toast({
            message: "请填写你的意见",
            position: "bottom",
            duration: 1500
          });
          return;
        }
        applyDeal({
          propertyNumber: this.applyDeal.propertyNumber,
          propertyState: this.applyDeal.status,
          opinion: this.applyDeal.opinion
        }).then(res => {
          if (res.respCode === "000000") {
            this.$toast({
              message: "处理成功",
              position: "bottom",
              duration: 1500
            });
            this.$refs.network2.init();
            this.closeMsgbox();
          }
        });
      }
    }
  }
};
</script>

<style lang="scss" scoped>
@import "./index.scss";
</style>
